#!/bin/sh

#GPIO_NUM = GPIOAA1 = GPIO_BASE + GPIOAA + 1 = 280 + 26 * 8 + 1 = 489
PGOOD_GPIO_BASE=$(cat /sys/class/gpio/gpiochip*/base)
PGOOD_GPIO_NUM=$(($PGOOD_GPIO_BASE + 26 * 8 + 1))
echo $PGOOD_GPIO_NUM > /sys/class/gpio/export
PGOOD_GPIO_PATH=/sys/class/gpio/gpio$PGOOD_GPIO_NUM
pgood=`cat $PGOOD_GPIO_PATH/value`
if [ $pgood -eq 0 ]
then
	exit 0
fi

#GPIO_NUM = GPIOAA7 = Base + GPIOAA + 7 = 280 + 26 * 8 + 7 = 495
GPIO_BASE=$(cat /sys/class/gpio/gpiochip*/base)
GPIO_NUM=$(($GPIO_BASE + 26 * 8 + 7))
GPIO_PATH=/sys/class/gpio/gpio$GPIO_NUM

sel_report_log POWER_CYCLE
touch /run/initramfs/power_reboot_flag

if [ ! -d "$GPIO_PATH" ];then
    echo $GPIO_NUM > /sys/class/gpio/export
    echo out >$GPIO_PATH/direction
fi

echo 0 > $GPIO_PATH/value 
sleep 5s 
echo 1 > $GPIO_PATH/value

sleep 6s

echo 0 > $GPIO_PATH/value 
sleep 1s 
echo 1 > $GPIO_PATH/value

exit 0